package com.gdut.simple.presenter.user;

import com.gdut.simple.R;
import com.gdut.simple.basic.BasicApplication;
import com.gdut.simple.common.NetworkUtils;
import com.gdut.simple.common.RequestCallback;
import com.gdut.simple.contract.FeedbackContract;
import com.gdut.simple.model.IFeedbackModel;
import com.gdut.simple.model.impl.FeedbackModelImpl;


public class FeedbackPresenter implements FeedbackContract.Presenter {

    private FeedbackContract.View mFeedbackView;
    private IFeedbackModel mFeedbackModel;

    public FeedbackPresenter(FeedbackContract.View view) {
        this.mFeedbackView = view;
        mFeedbackModel = new FeedbackModelImpl();
        mFeedbackView.setPresenter(this);
    }

    @Override
    public void feedback() {
        if (!NetworkUtils.isConnected(BasicApplication.getApplication())) {
            mFeedbackView.showMessage(BasicApplication.getApplication().getResources().getString(R.string.msg_error_net));
            return;
        }
        if (mFeedbackView.getContent() == null || mFeedbackView.getContent().isEmpty()) {
            mFeedbackView.showMessage("反馈的内容不能为空");
            return;
        }
        mFeedbackView.showProgress("提交中...");
        mFeedbackModel.feedback(mFeedbackView.getUser(),
                mFeedbackView.getContent(),
                mFeedbackView.getContact(),
                new RequestCallback<String>() {
                    @Override
                    public void onSuccess(String s) {
                        mFeedbackView.hideProgress();
                        mFeedbackView.showMessage("提交成功");
                        mFeedbackView.next();
                    }

                    @Override
                    public void onFailure(String message) {
                        mFeedbackView.hideProgress();
                        mFeedbackView.showMessage(message);
                    }
                });
    }

}
